package com.sne.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sne.sys.dto.SysParamDTO;
import com.sne.sys.entity.SysParam;
import com.sne.sys.mapper.SysParamMapper;
import com.sne.sys.service.ISysParamService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * 系统参数 服务实现类
 * @author fanghh
 * @since 2020-01-10
 */
@Service
public class SysParamServiceImpl extends ServiceImpl<SysParamMapper, SysParam>implements ISysParamService {

    @Override
    public IPage<SysParam> findPage(Page page, SysParamDTO entity) {
        LambdaQueryWrapper<SysParam> queryWrapper = Wrappers.<SysParam>query().lambda()
                .orderByDesc(SysParam::getCreateTime);
        if (entity.getState()!=null) {
            queryWrapper.eq(SysParam::getState, entity.getState());
        }
        if (StringUtils.isNotBlank(entity.getParamName())) {
            queryWrapper.like(SysParam::getParamName, entity.getParamName());
        }
        if (entity.getStartTime() != null) {
            queryWrapper.ge(SysParam::getCreateTime, entity.getStartTime());
        }
        if (entity.getEndTime() != null) {
            queryWrapper.le(SysParam::getCreateTime, entity.getEndTime());
        }
        return this.page(page,queryWrapper);
    }
}
